//
//  MainViewController.swift
//  CXWeibo
//
//  Created by mac on 15/6/6.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

import UIKit


class MainViewController: UITabBarController {

    @IBOutlet weak var mainTabBar: MainTabBar!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 添加子视图控制器
        addChildViewControllers()
        
        // 设置撰写按钮点击函数
        mainTabBar.composeButton.addTarget(self, action: "composeButtonClick", forControlEvents: UIControlEvents.TouchUpInside)
        
    }
    
    func composeButtonClick(){
    
        println(__FUNCTION__)
    }
    

    
    // 添加子控制器
     private func addChildViewControllers() {
    
        tabBar.tintColor = UIColor.orangeColor()
        
         addChildViewController("Home", "首页", "tabbar_home")
         addChildViewController("Message", "消息", "tabbar_message_center")
         addChildViewController("Discover", "发现", "tabbar_discover")
         addChildViewController("Profile", "我", "tabbar_profile")
    }
    
     private func addChildViewController(sbName: String, _ title: String, _ imageName: String) {
    
        let sb = UIStoryboard(name: sbName, bundle: nil)
        let nav = sb.instantiateInitialViewController() as! UINavigationController
        nav.title = title
        nav.topViewController.title = title
        nav.tabBarItem.image = UIImage(named: imageName)
        nav.tabBarItem.selectedImage = UIImage(named: imageName + "_highlighted")
        
        addChildViewController(nav)
        
    }
    
    
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
